package com.gxa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.vo.TransCondition;
import com.gxa.mapper.PatientCommonMapper;
import com.gxa.service.PatientCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PatientCommonServiceImpl implements PatientCommonService {


    @Autowired
    PatientCommonMapper patientCommonMapper;
    /**
     * 获取所有公海患者
     * @param currentPage 当前页
     * @param pageSize 每一页大小
     * @return
     */
    @Override
    public PageInfo getAllPatientList(Integer currentPage, Integer pageSize) {

        PageHelper.startPage(currentPage,pageSize);
        List list = patientCommonMapper.selectAllPatientList();

        PageInfo pageInfo = new PageInfo(list);

        return pageInfo;
    }

    /**
     * 分配患者给负责人
     * @param transCondition
     * @return
     */
    @Override
    public boolean assignPatients(TransCondition transCondition) {
        Integer integer = 0;

        List<Integer> patientIds = transCondition.getPatientIds();

        Integer userId = transCondition.getUserId();

        for(Integer patientId : patientIds){

            integer = patientCommonMapper.assignPatients(userId, patientId);

            integer++;
        }
        return integer>0?true:false;
    }

    @Override
    public boolean assignPatient(Integer userId, Integer patientId) {
        Integer integer = patientCommonMapper.assignPatients(userId, patientId);
        return integer>0?true:false;
    }

    @Override
    public PageInfo getCommonPatientList(Integer currentPage, Integer pageSize,String name) {

        PageHelper.startPage(currentPage,pageSize);
        List list = patientCommonMapper.selectCommonPatientList(currentPage, pageSize, name);

        PageInfo pageInfo = new PageInfo(list);

        return pageInfo;
    }

}
